<template>
	<div>
		<div>
			<el-button size="mini" @click="dataExport('pdf')">PDF</el-button>
			<el-button size="mini" @click="dataExport('xlsx')">Excel</el-button>
		</div>
		<iframe :src="reportUrl" style="width:100%;height:300px;margin-top: 10px;" ref="iframe"></iframe>
	</div>
</template>

<script>
	import constants from '@/utils/constants.js';
	import restUtil from '@/utils/restUtil.js';
	export default {
		name: "AttachmentPage",
		props: ["currentId", "para1"],
		data() {
			return {
				reportUrl: "",
			}
		},
		methods: {
			init() {
				var that = this;
				restUtil.getAction(this,"docreportpage/init?reportCode=" + this.para1 + "&recordId=" + this
						.currentId)
					.then(
						function(response) {
							if (response.data.code == 1) {
								var document = that.$refs.iframe.contentWindow.document;
								document.body.innerHTML = "";
								var html = "<html><body><style>" + response.data.style + "</style>" + response.data
									.content + "</body></html>";
								document.write(html);
							} else {
								that.$alert(response.data.message, '提示')
							}
						});
			},dataExport(format) {
				window.open(constants.ROOT_URL + "docreportpage/dataExport?reportCode=" + this.para1 + "&recordId=" + this
						.currentId+"&X-Token="+window.localStorage.getItem("token")+"&format="+format);
			}
		},
	}
</script>

<style>
</style>
